package com.clp.util.hutool.core.util;

import com.clp.util.hutool.core.text.ASCIIStrCache;

public class CharUtil {
    public static final char DOT = '.';
    public static final char SLASH = '/';
    public static final char BACKSLASH = '\\';
    public static final char DELIM_START = '{';
    public static final char SPACE = ' ';
    public static final char COMMA = ',';
    public static final char UNDERLINE = '_';
    public static final char LF = '\n';

    public static boolean isBlankChar(char c) {
        return isBlankChar((int) c);
    }

    /**
     * 是否空白符
     *  空白符包括空格、制表符、全角空格和不间断空格
     * @param c
     * @return
     */
    public static boolean isBlankChar(int c) {
        return Character.isWhitespace(c) || Character.isSpaceChar(c)
                || c == '\ufeff' || c == '\u202a';
    }

    /**
     * 获取给定字符的16进制数值（忽略大小写）
     *  如 A -> 10, B -> 11, ..., Z -> 35
     * @param b
     * @return
     */
    public static int digit16(byte b) {
        return Character.digit(b, 16);
    }

    public static boolean equals(char c1, char c2, boolean ignoreCase) {
        if (ignoreCase) {
            return Character.toLowerCase(c1) == Character.toLowerCase(c2);
        }
        return c1 == c2;
    }

    /**
     * 给定对象对应的类是否为字符类，字符类包括：
     *
     * <pre>
     * Character.class
     * char.class
     * </pre>
     *
     * @param value 被检查的对象
     * @return true表示为字符类
     */
    public static boolean isChar(Object value) {
        return value instanceof Character || value.getClass() == char.class;
    }

    public static String toString(char c) {
        return ASCIIStrCache.toString(c);
    }
}
